package com.yuyou.fn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Created by wens on 16-11-30.
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket smsApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("短信接口").forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/sms/.*"))
                .build().apiInfo(apiInfo());
    }

    @Bean
    public Docket adminApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("后台接口").forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/admin/.*"))
                .build().apiInfo(apiInfo());
    }


    @Bean
    public Docket qiniuApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("七牛上传token接口").forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/qiniu/.*"))
                .build().apiInfo(apiInfo());
    }

    @Bean
    public Docket mApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("移动端接口").forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/m/.*"))
                .build().apiInfo(apiInfo());
    }


    private ApiInfo apiInfo() {
        Contact contact=new Contact("wens","www.google.com","wenzuojing@gmail.com");
        ApiInfo apiInfo = new ApiInfoBuilder().license("Apache License Version 2.0").title("云课堂").description("云课堂后台接口").contact(contact).version("1.0").build();
        return apiInfo;
    }
}
